<?php

class RecoveryForm extends CFormModel {
	public $email, $user;
	
	public function rules() {
		return array(
			array('email', 'required'),
			array('email', 'email', 'message' => UserModule::t('email введен неверно.')),
			array('email', 'checkexists'),
		);
	}
	
	public function attributeLabels() {
		return array(
			'email'=>UserModule::t("email"),
		);
	}
	
	public function checkexists($attribute,$params) {
		if ($this->hasErrors()) return false;
		$user = Users::model()->findByAttributes(array('username'=>$this->email));
		if ($user === null)	{
			$this->addError("email", UserModule::t('Такой email не найден в нашей системе.'));
			return false;
		}
		if ($user) $this->user = $user;
		return true;
	}
	
}